// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: V Platform 2 Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 50 : TYPE_VPLATFORM2

// Function declarations
reserve function VPlatform2_DebugDraw
reserve function VPlatform2_DebugSpawn

// Static Values

// Tables

function VPlatform2_DebugDraw
	DrawSprite(0)
end function


function VPlatform2_DebugSpawn
	CreateTempObject(TypeName[V Platform 2], 0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.ypos
	object[tempObjectPos].propertyValue = object.direction
end function


event ObjectMain
	temp7 = object.ypos
	GetTableValue(temp0, 12, StageSetup_table9)
	if object.propertyValue == 1
		FlipSign(temp0)
		temp0 += 0x4000
	else
		temp0 -= 0x4000
	end if
	temp0 <<= 7
	object.ypos = object.value0
	object.ypos -= temp0
	temp1 = object.ypos
	temp7 &= -0x10000
	object.value1 = object.ypos
	object.value1 &= -0x10000
	object.value1 -= temp7
	object.ypos = temp7
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(object[currentPlayer].state, PlayerObject_HandleMonikaTeleport)
		temp7 = checkResult
		CheckLower(object[0].value1, 20)
		temp7 &= checkResult
		if temp7 == 0	
			BoxCollisionTest(C_BOX, object.entityPos, -32, -2, 32, 138, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -2, 32, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].ypos += object.value1
			end if
		end if	
		if object[currentPlayer].state == PlayerObject_HandleMonikaTeleport
			if object[0].value1 >= 17
				BoxCollisionTest(C_TOUCH, object.entityPos, -32, -2, 32, 138, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object[currentPlayer].xpos > object.xpos
						object[currentPlayer].ixpos = object[currentPlayer].collisionLeft
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos += 0x320000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel < 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					else
						object[currentPlayer].ixpos = object[currentPlayer].collisionRight
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos -= 0x320000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel > 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					end if
				end if
			end if
		end if		
	next
	object.ypos = temp1
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("GHZ/Objects.gif")
	SpriteFrame(-32, -8, 64, 144, 191, 1)
	foreach (TypeName[V Platform 2], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].ypos
	next
	SetTableValue(TypeName[V Platform 2], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VPlatform2_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VPlatform2_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
